package com.ls.spring.bean;

import java.util.List;

/**
 * 2022-3-4
 * Hello组件
 */
public class Hello {
    private String name;
    private int age;
    private Person person1;
    private List<String> Hero;

    public Hello(){
        System.out.println("私有的构造函数\r\n");
    }

    /**
     * 使用静态工厂方法创建
     * @return
     */
    public static Hello HelloFactory(){
        System.out.println("使用静态工厂方法创建创建hello对象");
        return new Hello();
    }

    //使用构造方法执行DI注入
    public Hello(String name){
        System.out.println("有参构造函数进行DI注入\r\n");
        this.name = name;
    }

    //使用重载的构造方法执行DI注入
    public Hello(int age, String name){
        System.out.println("========对象已创建  int age, String name============\r\n");
        this.age = age;
        this.name = name;
    }

    public Hello(String name, int age){
        System.out.println("========对象已创建  String name, int age============\r\n");
        this.name = name;
        this.age = age;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public List<String> getHero() {
        return Hero;
    }

    public void setHero(List<String> hero) {
        Hero = hero;
    }

    public void setPerson1(Person person1) {
        this.person1 = person1;
    }

    public void sayHello(){
        if(this.person1 == null){
            String name = this.name == null ? "李哥" : this.name;
            int age = this.age == 0 ? 18 : this.age;
            System.out.println("你好啊我是" + name + ",今年" + age + "岁" );
        }else{
            String name = this.person1.getName() == null ? "李哥" : this.person1.getName();
            int age = this.person1.getAge() == 0 ? 18 : this.person1.getAge();
            char gender = this.person1.getGender() == '0' ? '男' : '女';
            System.out.println("你好啊我是" + name + ",今年" + age + "岁。性别" + gender );
        }
    }
}
